home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WW3DKit / WW3DCompoundCommand.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  7.6 KB  |  332 lines

  1.  
  2. #import "WW3DCompoundCommand.h"
  3.  
  4. @implementation WW3DCompoundCommand
  5.  
  6. + initialize { return [WW3DCompoundCommand setVersion:1], self; }
  7.  
  8. - init
  9. {
  10.   [super init];
  11.  
  12.   ribCommandList  = [[RIBCommandList alloc] init];
  13.   dirtyBoundingBox = YES;
  14.   
  15.   return self;
  16. }
  17.  
  18.  
  19. - awake
  20. {
  21.     [super awake];
  22.     dirtyBoundingBox = YES;
  23.     return self;
  24. }
  25.  
  26.  
  27. - setRIBCommandList:newRIBCommandList { ribCommandList = newRIBCommandList; return self; }
  28. - ribCommandList { return ribCommandList; }
  29.  
  30. - copyFromZone:(NXZone *)zone
  31. {
  32.    id   newCopy = [super copyFromZone:zone];
  33.    id   newList = [[self ribCommandList] copyFromZone:zone];
  34.  
  35.  
  36.    //NXLogError("WW3DCompoundCommand: my list is %p - the copy is %p", ribCommandList, newList);
  37.    [newCopy setRIBCommandList:newList];
  38.    return newCopy;
  39. }
  40.  
  41. // see, this is potentially interesting, if a simple linear
  42. // interpolation of my ribCommandList did not represent the appropriate
  43. // linear interpolation of me, I could interpose some other list of
  44. // objects.  For example, there might some discontinuity between
  45. // this instance and "b", such as an enumerated 
  46. // parameter (i.e. "sleepy, grumpy, happy, ecstatic") which doesn't
  47. // have an obvious interpolation.  
  48. // In the case of this simple composite object, however, 
  49. // it is true that simply interpolating my ribCommandList is enough.
  50. - lerpWith:b by:(float)uValue
  51. {
  52.    id  newMe = nil, newRIBCommandList;
  53.  
  54.  
  55.    if (([self class] != [b class]) || (uValue <= 0.0))
  56.    {  return self;
  57.    }
  58.  
  59.    if (uValue >= 1.0)
  60.    {  return b;
  61.    }
  62.  
  63.    newMe = [self copyFromZone:[self zone]];
  64.    newRIBCommandList = [ribCommandList lerpWith:[b ribCommandList] by:uValue];
  65.    [[newMe ribCommandList] empty];
  66.    [newMe setRIBCommandList:newRIBCommandList];
  67.  
  68.    return newMe;
  69. }
  70.  
  71. - lerpSelfWith:b by:(float)uValue
  72. {
  73.    if (([self class] != [b class]) || (uValue <= 0.0))
  74.    {  return self;
  75.    }
  76.  
  77.    if (uValue >= 1.0)
  78.    {  return b;
  79.    }
  80.  
  81.    [ribCommandList lerpSelfWith:[b ribCommandList] by:uValue];
  82.  
  83.    return self;
  84. }
  85.  
  86. - (BOOL)isLerpable { return YES; }
  87.  
  88. - (BOOL)pushesOrPopsCTM { return NO; }
  89. - (BOOL)pushesCTM { return NO; }
  90. - (BOOL)popsCTM { return NO; }
  91.  
  92. - free
  93. {
  94.     [ribCommandList free];
  95.     return [super free];
  96. }
  97.  
  98. - (BOOL)hasBoundingBox        { return YES; }
  99. - (BOOL)isMotionBlurrable    { return YES; }
  100. - (BOOL)isCompoundCommand    { return YES; }
  101.  
  102. - setBoundingBox:(RtBound *)newBoundingBox
  103. {
  104.     N3D_CopyBound(*newBoundingBox, boundingBox);
  105.     return self;
  106. }
  107.  
  108. - calculateBoundingBoxStartingAt:(RtFloat)shutterOpenTime endingAt:(RtFloat)shutterCloseTime  
  109. {  
  110.     dirtyBoundingBox = NO;
  111.     return [self setBoundingBox:[ribCommandList boundingBoxStartingAt:shutterOpenTime endingAt:shutterCloseTime]];
  112. }
  113.  
  114. - (RtBound *)boundingBoxStartingAt:(RtFloat)intervalStartTime endingAt:(RtFloat)intervalEndTime
  115.    if (dirtyBoundingBox) 
  116.    {  [self calculateBoundingBoxStartingAt:intervalStartTime endingAt:intervalEndTime];
  117.    }
  118.    return &boundingBox; 
  119. }
  120.  
  121. - (float)lastSampleIsAt { return 0.0; }
  122.  
  123. - (unsigned long int)maxSampleBandwidth { return [ribCommandList maxSampleBandwidth]; }
  124.  
  125. - setMyShape:shape
  126. {
  127.     myShape = shape;
  128.     return self;
  129. }
  130.  
  131. - shape
  132. {
  133.     return myShape;
  134. }
  135.  
  136. - renderMaps:(WW3DCamera *)camera
  137.     startingAt:(RtFloat)shutterOpenTime
  138.     endingAt:(RtFloat)shutterCloseTime usingStream:(NXStream *)ns
  139. {
  140.     return self;
  141. }
  142.  
  143. - renderMaps:(WW3DCamera *)camera usingStream:(NXStream *)ns
  144. {
  145.     return self;
  146. }
  147.  
  148. - renderMaps:(WW3DCamera *)camera
  149.     startingAt:(RtFloat)shutterOpenTime
  150.     endingAt:(RtFloat)shutterCloseTime
  151. {
  152.     return self;
  153. }
  154.  
  155. - renderMaps:(WW3DCamera *)camera
  156. {
  157.     return self;
  158. }
  159.  
  160. - renderSelfAsBox:(WW3DCamera *)camera
  161.     startingAt:(RtFloat)shutterOpenTime
  162.     endingAt:(RtFloat)shutterCloseTime
  163. {
  164.     return [ribCommandList renderSelfAsBox:camera
  165.                startingAt:shutterOpenTime
  166.                endingAt:shutterCloseTime];
  167. }
  168.  
  169. - renderSelf:(WW3DCamera *)camera
  170.     startingAt:(RtFloat)shutterOpenTime
  171.     endingAt:(RtFloat)shutterCloseTime
  172. {
  173.     return [ribCommandList renderSelf:camera
  174.                startingAt:shutterOpenTime
  175.                endingAt:shutterCloseTime];
  176. }
  177.  
  178. - renderSelf:(WW3DCamera *)camera
  179. {
  180.     return [ribCommandList renderSelf:camera];
  181. }
  182.  
  183. - preRenderSelf:(WW3DCamera *)camera
  184.     startingAt:(RtFloat)shutterOpenTime
  185.     endingAt:(RtFloat)shutterCloseTime
  186. {
  187.     return [ribCommandList preRenderSelf:camera
  188.                startingAt:shutterOpenTime
  189.                endingAt:shutterCloseTime];
  190. }
  191.  
  192. - preRenderSelf:(WW3DCamera *)camera
  193. {
  194.     return [ribCommandList preRenderSelf:camera];
  195. }
  196.  
  197. - transformCTM:(WW3DAttributeState *)attributeState
  198.     startingAt:(RtFloat)shutterOpenTime
  199.     endingAt:(RtFloat)shutterCloseTime 
  200. {
  201.     return [ribCommandList transformCTM:attributeState
  202.                            startingAt:shutterOpenTime
  203.                endingAt:shutterCloseTime]; 
  204. }
  205.  
  206. // methods to make me look like a compound command:
  207. - (int)count {  return [ribCommandList count]; }
  208. - objectAt:(int)i {  return [ribCommandList objectAt:i]; }
  209.  
  210.  
  211. // WavesWorld archiving:
  212. // writeEve:(NXStream *)stream
  213. // writeScene:(NXStream *)stream
  214.  
  215. - writeEve:(NXStream *)stream atTabLevel:(int)tab
  216. {
  217.     int  i;
  218.     
  219.     for (i = 0; i < tab; i++) {
  220.     NXPrintf(stream, "\t");
  221.     }
  222.     NXPrintf(stream, "#WW3DCompoundCommand");
  223.     return self;
  224. }
  225.  
  226. - writeScene:(NXStream *)stream atTabLevel:(int)tab
  227. {
  228.     int  i;
  229.     
  230.     for (i = 0; i < tab; i++) {
  231.     NXPrintf(stream, "\t");
  232.     }
  233.     NXPrintf(stream, "#WW3DCompoundCommand");
  234.     return self;
  235. }
  236.  
  237. - write3DTextScene:(NXStream *)stream atTabLevel:(int)tab index:(int)index time:(float)time until:(float)lastTime
  238. {
  239.    int  i;
  240.  
  241.  
  242.    for (i = 0; i < tab; i++)
  243.    {  NXPrintf(stream, "\t");
  244.    }
  245.  
  246.    NXPrintf(stream, "startShape %s; ", [[self class] name]);
  247.    // need tab
  248.    // need index (position in current list)
  249.    NXPrintf(stream, 
  250.         "EveCmd {Translate [expr { %d * $__text__(tabLength)}] [expr {$__text__(spacingFactor) * %d * $__text__(spacing) * $__text__(fontSize)}] 0 };\n", 
  251.             tab, index); 
  252.    NXPrintf(stream, "  EveCmd {WW3DText $__text__(fontName) $__text__(fontSize) {");
  253.    [self writeEve:stream atTabLevel:tab];
  254.    NXPrintf(stream, "} left;}\n");
  255.   NXPrintf(stream, "endShape;\n");
  256.  
  257.   return self;
  258. }
  259.  
  260. - writeInventorAtTime:(float)currentTime to:(NXStream *)stream atTabLevel:(int)tab
  261. {
  262.    int  i;
  263.  
  264.  
  265.    for (i = 0; i < tab; i++)
  266.    {  NXPrintf(stream, "\t");
  267.    }
  268.    NXPrintf(stream, "# ");
  269.    [self writeEve:stream atTabLevel:tab];
  270.    NXPrintf(stream, "\n");
  271.  
  272.    return [ribCommandList writeInventorAtTime:currentTime to:stream atTabLevel:tab];
  273. }
  274.  
  275. #define typeVector "@"
  276. #define typeValues &ribCommandList
  277.  
  278. - read:(NXTypedStream *)stream 
  279. {
  280.     int version;
  281.     
  282.     [super read:stream];
  283.     version = NXTypedStreamClassVersion(stream,"WW3DCompoundCommand");
  284.     if (version == 0) NXReadTypes(stream, "i", &version), version = 1;
  285.     if (version == 1)
  286.     {  NXReadTypes(stream, typeVector, typeValues);
  287.        NXReadArray(stream, "f", 6, boundingBox);
  288.        myShape = NXReadObject(stream);
  289.     }
  290.  
  291.     return self;
  292. }
  293.  
  294. - write:(NXTypedStream *)stream 
  295. {
  296.     [super write:stream];
  297.     NXWriteTypes(stream, typeVector, typeValues);
  298.     NXWriteArray(stream, "f", 6, boundingBox);
  299.     NXWriteObjectReference(stream, myShape);
  300.     return self;
  301. }
  302.  
  303. - (BOOL)theSameAs:otherRIBCommand
  304. {
  305.   if ([self class] != [otherRIBCommand class])
  306.   {  return NO;
  307.   }
  308.  
  309.   return [ribCommandList theSameAs:[otherRIBCommand ribCommandList]];
  310. }
  311.  
  312. - (BOOL)similarTo:otherRIBCommand 
  313. {
  314.   if ([self class] != [otherRIBCommand class])
  315.   {  return NO;
  316.   }
  317.   return YES;
  318. }
  319.  
  320. - (BOOL)isMoot
  321. {
  322.   return [ribCommandList isMoot];
  323. }
  324.  
  325. - (BOOL)isMootStartingAt:(float)startTime endingAt:(float)endTime  {  return [self isMoot];  }
  326.  
  327. // boy, this is dumb... This is to get around the stupid warnings from the compiler - ask wave for details
  328. - class { return [super class]; }
  329.  
  330. @end
  331.